package com.zhou.common.quartz.test.quartz;

import com.zhou.common.quartz.test.quartz.jobclass.MySampleJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xianfeng
 * @date 2023/12/20 22:00
 * @description:
 */
@Configuration
public class Job1Config {
    private static final String ID = "FIRST_JOB";

    @Bean
    public JobDetail jobDetail1() {
        return JobBuilder.newJob(MySampleJob.class)
                .withIdentity(ID + " 01")
                .usingJobData("index", 1)
                .storeDurably()
                .build();
    }

    @Bean
    public Trigger trigger1() {
        // 简单的调度计划的构造器
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(20) // 频率
                .repeatForever(); // 次数

        return TriggerBuilder.newTrigger()
                .forJob(jobDetail1())
                .withIdentity(ID + " 01Trigger")
                .withSchedule(scheduleBuilder)
//                .usingJobData("index", 1)
                .startNow()
                .build();
    }
}
